/**
 * Copyright (c)  TMA Mobile Solutions, TMA Solutions company. All Rights Reserved.
 * This software is the confidential and proprietary information of TMA Solutions, 
 * ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it only in accordance 
 * with the terms of the license agreement you entered into with TMA Solutions.
 *
 *
 * TMA SOLUTIONS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, 
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. TMA SOLUTIONS SHALL NOT BE LIABLE FOR ANY DAMAGES 
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES
 */
package com.example.pregnant.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.SimpleAdapter.ViewBinder;

import com.example.pregnant.R;
import com.example.pregnant.Settings;

/** 
 * Class description: TODO
 * 
 * @created           May 18, 2011
 * @version 		  v2.0
 * @author 			  TMS
 * @copyright         TMA Solutions, www.tmasolutions.com
 */
public class HomeScreen extends Activity implements OnClickListener{

	Button btBaby, btMommy, btImage;
	TextView barText;
	ProgressBar ageBar;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.homescreen);
		
		btBaby = (Button) findViewById(R.id.btBaby);
		btMommy = (Button) findViewById(R.id.btMommy);
		btImage = (Button) findViewById(R.id.btImage);
		btBaby.setOnClickListener(this);
		btMommy.setOnClickListener(this);
		btImage.setOnClickListener(this);
		
		
		barText = (TextView) findViewById(R.id.TitleBarText);
		barText.setText("Màn hình chính");
		
		ageBar = (ProgressBar) findViewById(R.id.prgressBar);
		ageBar.setMax(40);
		ageBar.setProgress(Settings.getWeekAge());
		ageBar.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(getApplicationContext(), "Bé còn " + (40-Settings.getWeekAge()) + " tuần nữa sẽ ra đời!", 1000).show();
			}
		});
//		Toast.makeText(getApplicationContext(), "Remain days : " + Settings.getRemainDays(), 1000).show();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btBaby:
			startActivity(new Intent(getApplicationContext(), BabyScreen.class));
			break;
		case R.id.btMommy:
			startActivity(new Intent(getApplicationContext(), MommyScreen.class));
			break;
		case R.id.btImage:
			startActivity(new Intent(getApplicationContext(), ImageScreen.class));
			break;
		
		}
		
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuItem resetAge = menu.add("Nhập lại tuần tuổi");
		resetAge.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			@Override
			public boolean onMenuItemClick(MenuItem item) {
				SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
				Editor editor = settings.edit();
				editor.putBoolean(Settings.IS_STARTED, false);
//				editor.putInt(Settings.WEEK_AGE, 0);
				editor.commit();
				
				Intent i = new Intent();
				i.setClass(getApplicationContext(),PregnantCalendar.class);
				startActivity(i);
				finish();
				return false;
			}
		});
		return true;
		
	}
}
